/*
 * MapBufferWorker.java
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.apps.admin.gui.map;

import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingWorker;

/**
 *
 * @author demory
 */
public class MapBufferWorker extends SwingWorker<Integer, Void> {

  private MapPanel panel_;

  public MapBufferWorker(MapPanel panel) {
    panel_ = panel;
  }

  @Override
  protected Integer doInBackground() throws Exception {

    int d;
    for (d = 0; d < 8; d++) {
      initTile(d, true);
      if (this.isCancelled()) {
        System.out.println("CANCELLED");
        return d;
      }

    }
    return d;
  /*Image[] imgs = new Image[8];
  return imgs;*/
  }

  private void initTile(int dir, boolean sleep) {
    //try {
    panel_.getBuffer().initTile(dir);
  //System.out.println("buffered "+dir);
  //panel_.repaint();
  //if(sleep) sleep(100);
  //} catch (InterruptedException ex) {
  //  Logger.getLogger(MapBufferThread.class.getName()).log(Level.SEVERE, null, ex);
  //}
  }

  @Override
  protected void done() {
    try {
      int numProcessed = get();
      System.out.println("numProcessed=" + numProcessed);
    } catch (InterruptedException ex) {
      Logger.getLogger(MapBufferWorker.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ExecutionException ex) {
      Logger.getLogger(MapBufferWorker.class.getName()).log(Level.SEVERE, null, ex);
    } catch (CancellationException e) {
    }


  }
}
